package zb.stream;

import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author wzby
 * @Date: 2022/8/6 9:31
 */
public class Stream2 {
    public static void main(String[] args) {
        IntStream is1 = IntStream.range(1,6);
        //.range在范围内以1的增量返回值
        IntStream is2 = IntStream.rangeClosed(15,20);
        is1.forEach(System.out::println);
       // is2.forEach(System.out::println);
        //System.out.println(is2.sum());
        int sum = is2.filter(e -> e % 2 == 0).sum();
        System.out.printf("偶数之和为%d %n",sum);

        System.out.println("-=-=".repeat(20));

        Stream<User> su = Stream.of(new User("狗蛋",1,17),new User("狗牙",2,18),new User("来福",3,46),new User("爱喜",4,24));
        su.map(s -> {
            if(s.getName().startsWith("狗")){
                s.setAge(s.getAge()+10);
            }
            return s;
        }).forEach(System.out::println);
    }
}
